class AttrCtrl extends ScrollList {
	bindJson(data: any): void {
		// console.log("bind_json",data)
		const list = [];
		for (const [key, value] of Object.entries(data)) {
		// for (const key in data) {
			// const value = data[key];
			list.push({ key, value, attr: this });
		}
		this.list.dataProvider = new eui.ArrayCollection(list);
	}

	protected override childrenCreated(): void {
		super.childrenCreated();
		this.list.itemRenderer = AttrItem;
		this.list.useVirtualLayout = false;// 不对显示优化了
	}

	static inputEnterEvent = 'ENV_ATTRCTRL_INPUTENTER'

	onEnter(item: AttrItem): void {
		this.dispatchEventWith(AttrCtrl.inputEnterEvent, false, item);
	}

	onTab(item: AttrItem, shift: boolean): void {
		const list = this.allItems();
		const index = list.indexOf(item);
		const next = shift ? index - 1 : index + 1;
		console.log('AttrCtrl.onTab', item.data, shift, index, next);
		if (list[next]) {
			// list[next].value.textDisplay.setFocus() bug!
		}
	}

	allItems(): AttrItem[] {
		const list = [];
		for (const c of this.list.$children) {
			if (c instanceof AttrItem) { list.push(c); }
		}
		return list;
	}

	findAttr(name: string): AttrItem {
		for (const c of this.list.$children) {
			if (c instanceof AttrItem) {
				if (c.key.text === name) { return c; }
			}
		}
		return null;
	}
}
